package com.javaweb.api.controller;

import com.javaweb.api.dto.MqttParamDto;
import com.javaweb.api.service.IMqttSenderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program javaweb
 * @description: mock
 * @author: JiaLe.Liu
 * @create: 2021.12.05 09:08
 */
@RestController
@RequestMapping("/mqtt")
@Slf4j
public class MqttMockController {
    /**
     * 注入发送MQTT的Bean
     */
    @Resource
    private IMqttSenderService iMqttSenderService;

    // 发送自定义消息内容（使用默认主题）
    @PostMapping("/send")
    public void test1(@RequestParam String data) {
        iMqttSenderService.sendToMqtt(data);
    }

    // 发送自定义消息内容，且指定主题
    @RequestMapping("/sendData")
    public void test2(@RequestBody MqttParamDto mqttParamDto) {
        iMqttSenderService.sendToMqtt(mqttParamDto.getTopic(), mqttParamDto.getData().toJSONString());
    }
}
